package com.example.javamediaserver.model;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.LocalDateTime;

@Entity
@Table(name = "stream_sessions")
@Data
public class StreamSession {

    @Id
    private String id;
    
    private String streamPath;
    private String app;
    private String streamKey;
    private String clientIp;
    private String clientInfo;
    
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    
    private boolean isRecording;
    private String recordingPath;
    
    // 计算流会话时长（秒）
    public long getDurationInSeconds() {
        if (endTime == null) {
            return java.time.Duration.between(startTime, LocalDateTime.now()).getSeconds();
        }
        return java.time.Duration.between(startTime, endTime).getSeconds();
    }
    
    // 从流路径解析应用名和流密钥
    public void parseStreamPath() {
        if (streamPath != null && streamPath.startsWith("/")) {
            String[] parts = streamPath.substring(1).split("/");
            if (parts.length > 0) {
                this.app = parts[0];
            }
            if (parts.length > 1) {
                this.streamKey = parts[1];
            }
        }
    }
} 